//
//  BADiscountsView.m
//  YunFu
//
//  Created by Bager on 2018/9/4.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BADiscountsView.h"

#import "BADiscountsCell.h"

@implementation BADiscountsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        [self createView];
        [self createTitleView];
    }
    return self;
}

- (void)createTitleView
{
    UILabel *labelDown = [[UILabel alloc] initWithFrame:CGRectMake(kPublicMargin, 0, 100, 44)];
    labelDown.text = @"超值特惠";
    labelDown.font = [UIFont systemFontOfSize:14];
    labelDown.textColor = HexColor(0x2ea9f7);
    labelDown.adjustsFontSizeToFitWidth = YES;
    [self addSubview:labelDown];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setFrame:CGRectMake(kScreenWidth - kPublicMargin - 40, 0, 40, 44)];
    [btn setTitle:@"更多 >" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(moreClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
}

- (void)moreClick
{
    
}

- (void)createView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2 - 10) / 3.0, 140);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 5;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.shopCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kPublicMargin, 44, kScreenWidth - kPublicMargin * 2, 140)  collectionViewLayout:flowLayout];
    
    self.shopCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.shopCollectionView.dataSource = self;
    
    self.shopCollectionView.delegate = self;
    
    [self.shopCollectionView registerClass:[BADiscountsCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    
    [self addSubview:self.shopCollectionView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BADiscountsCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
    NSArray *imgArray = @[@"yf2-mddh1-9",@"yf2-mddh1-9",@"yf2-mddh1-9"];
    NSArray *nameArray = @[@"张氏自主骨头",@"张氏自主骨头",@"张氏自主骨头"];
    NSArray *detailArray = @[@"¥88",@"¥88",@"¥88"];
    NSArray *typeArray = @[@"¥188",@"¥188",@"¥188"];
    
    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    cell.name.text = nameArray[indexPath.item];
    cell.detail.text = detailArray[indexPath.item];
    cell.type.text = typeArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
